<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/tag.jsp"%>
<html>
  <head>
    <title>系统登陆</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

<%@ include file="/common/common_css.jsp"%>
<%@ include file="/common/common_js.jsp"%>
<LINK rel="stylesheet" type="text/css" href="${baseurl}/styles/login.css">

<STYLE type="text/css">
.btnalink {
	cursor: hand;
	display: block;
	width: 80px;
	height: 29px;
	float: left;
	margin: 12px 28px 12px auto;
	line-height: 30px;
	background: url('${baseurl}/images/login/btnbg.jpg') no-repeat;
	font-size: 14px;
	color: #fff;
	font-weight: bold;
	text-decoration: none;
}
</STYLE>
<%-- <% 
	String capstr = (String)session.getAttribute("validateCode");

%> --%>
<script type="text/javascript">

	/* 回车确认 */
    $(document).keyup(function(e){

	 var curKey = e.which; 

	     if(curKey==13){
	      //调用查询方法
	      loginsubmit();
	     }
	 })
	//登录
	function loginsubmit() {
		//jquerySubByFId('loginform', login_commit_callback, null, "json");
    	var username = $("[name=username]").val();
		var password = $("[name=password]").val();
		//var validateCode = $("[name=validateCode]").val();
		if(!checkNull('username') && !checkNull('password')){
			$.messager.alert('错误',"用户名密码不能为空！");
			return false;
		}else{
			$.ajax({
				   type: "POST",
				   url: "${pageContext.request.contextPath}/salesman/login",
				   data: {username:username,password:password},
				   success: function(data){
					   if(data.status == '000'){
						window.location.href='${pageContext.request.contextPath}/page/index'
						}else if(data.status == '001'){
							$.messager.alert('系统提示',data.msg);
							
						}else if(data.status == '002'){
							$.messager.alert('系统提示',data.msg);
						}else{
							$.messager.alert('系统提示','登录异常!');
							}
				   },
				   error: function(){
					   $.messager.alert('提示','登录失败!');
				   }
				});
		}
		//window.location.href="/rest/page/index";
	}
	/* 重置 */
	function reset2(){
		$('#username').val("");
		$('#password').val("");
		}
  //自定义判空封装方法
	function checkNull(id){
		var val = trim($("#"+id).val());
		$("#"+id).val(val);
		if(val == null || val.length == 0){
			return false;
		}else{
			return true;
		}
	}
	//去空格  
	function trim(str){       
  		return str.replace(/^(\s|\u00A0)+/,'').replace(/(\s|\u00A0)+$/,'');       
	}

	/* $("#login").click(function(){
		var username = $("[name=usercode]").val();
		var password = $("[name=password]").val();
		
		if(username!="admin" || password!="admin"){
			$.messager.alert('错误',"用户名密码不正确！");
			return ;
		}
		window.location.href="/rest/page/index";
	}); */
	function randomcode_refresh() {
		//因为更改src时重新向服务端发起get请求，get请求存在缓存 问题，添加时间戳解决缓存问题
		$("#randomcode_img").attr('src',
				'${baseurl}/auth/validatecode.jsp?time' + new Date().getTime());
	}
	function tofirst(){
		if(parent.parent.parent){
			parent.parent.parent.location='${baseurl}/';
		}else if(parent.parent){
			parent.parent.location='${baseurl}/';
		}else if(parent){
			parent.location='${baseurl}/';
		}else{
			window.location='${baseurl}/';
		} 
		//window.location='${baseurl}/';
	}
</SCRIPT>
</HEAD>
<BODY style="background: #f6fdff url(${baseurl}/images/login/bg1.jpg) repeat-x;">
	<FORM id="loginform" name="loginform" action="${baseurl}/auth/login.action"
		method="post">
		<DIV class="logincon">

			<DIV class="title">
				<IMG alt="" src="">
			</DIV>

			<DIV class="cen_con">
				<IMG alt="" src="${baseurl}/images/login/bg2.png">
			</DIV>

			<DIV class="tab_con">

				<input type="password" style="display:none;" />
				<TABLE class="tab" border="0" cellSpacing="6" cellPadding="8">
					<TBODY>
						<TR>
							<TD>用户名：</TD>
							<TD colSpan="2"><input type="text" id="username"
								name="username" style="WIDTH: 130px" value="admin"/></TD>
						</TR>
						<TR>
							<TD>密 码：</TD>
							<TD><input type="password" id="password" name="password" style="WIDTH: 130px" value="admin"/>
							</TD>
						</TR>
						<%-- <TR>
							<TD>验证码：</TD>
							<TD><input id="randomcode" name="validateCode" size="8" /> <img
								id="randomcode_img" src="${baseurl}/auth/validatecode.jsp" alt=""
								width="56" height="20" align='absMiddle' /> <a
								href=javascript:randomcode_refresh()>刷新</a></TD>
						</TR> --%>

						<TR>
							<TD colSpan="2" align="center"><input type="button"
								class="btnalink" onclick="loginsubmit()" value="登&nbsp;&nbsp;录" />
								<input type="button" onclick="reset2()" class="btnalink" value="重&nbsp;&nbsp;置" /></TD>
						</TR>
					</TBODY>
				</TABLE>

			</DIV>
		</DIV>
	</FORM>
</BODY>
</HTML>
